/* Project cyclecounter03
PIC16F877A
*/
#include <pic.h>
#include "font7s.h"
__CONFIG(
PWRTEN
& BORDIS
& UNPROTECT
& WDTDIS
& LVPDIS
& HS
);
__IDLOC(F877);
#define BCD_A RC0
#define BCD_B RC1
#define BCD_C RC2
#define BCD_D RC3
#define CK RC5
#define RES RA5
#define LED1 RB5
#define LED2 RB4
#define LED3 RB3
#define LED4 RB2
#define LED5 RB1
#define LED6 RB0
unsigned char dig7;
unsigned char ptn7[7];
unsigned char sel7[] = {
0b00000001,
0b00000010,
0b00000100,
0b00001000,
0b00010000,
0b00100000,
0b01000000
};
unsigned char x[7];
unsigned char i, A, B, C, D;
void interrupt entry(void){
if(TMR1IF){
TMR1IF = 0;
CK = 1;
NOP();
CK = 0;
NOP();
RES = 1;
NOP();
RES = 0;
NOP();
TMR1H = 158; TMR1L = 115;
}
}
void main(void){
CMCON = 0b00000111;
ADCON0 = 0b10000000;
T1CON = 0b00000001;
PIE1 = 0b00000001;
INTCON = 0b01000000;
TMR1IF = 0;
ei();
OPTION = 0b10000010;
PORTA = 0;
TRISA = 0b00000000;
PORTB = 0;
TRISB = 0b00000000;
PORTD = 0;
TRISD = 0b00000000;
PORTC = 0;
TRISC = 0b00001111;
PORTE = 0;
TRISE = 0b00000000;
while(1){
for(dig7 = 0; dig7 < 7; dig7++){
if(BCD_A) {
A = 1;
} else {
A = 0;
}
if(BCD_B) {
B = 1;
} else {
B = 0;
}
if(BCD_C) {
C = 1;
} else {
C = 0;
}
if(BCD_D) {
D = 1;
} else {
D = 0;
}
x[dig7] = D*8 + C*4 + B*2 + A;
if(x[6] == 0){
ptn7[6] = FONT7S_BLANK;
if(x[5] == 0){
ptn7[5] = FONT7S_BLANK;
if(x[4] == 0){
ptn7[4] = FONT7S_BLANK;
if(x[3] == 0){
ptn7[3] = FONT7S_BLANK;
if(x[2] == 0){
ptn7[2] = FONT7S_BLANK;
}
}
}
}
}
ptn7[dig7] = font7s[x[dig7]];
PORTD = ptn7[dig7 + 1];
PORTB |= sel7[dig7];
for(i = 0; i < 10; i++){
for(i = 0; i < 10; i++){
NOP();
}
}
PORTB &= ~sel7[dig7];
}
}
}